package dao.Frame;


import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JTextArea;

import dao.hero.BaseHero;
import dao.hero.Dongji;
import dao.hero.Guanghua;
import dao.hero.Jianwei;
import dao.hero.Xinlin;




import dao.hero.Zhiguo;
import dao.hero.Zhihai;

import java.awt.event.MouseEvent;

/**
 * @author 张新林
 * 时间 2015年3月21日下午6:18:07
 * 包名 dao.Frame
 * 类名 SelectFrame
 * 选择英雄的界面
 * 选择自己操作的英雄以及电脑操作的英雄
 */
public class SelectFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3694276472987630787L;
	private JPanel contentPane;
	final int hero_sum=6;   //英雄总数
	int ordernum=1;
	BaseHero hero;
	BaseHero hero2;
	JButton enterGame;
	JLabel head_label;
	JLabel bluelabel;
	JLabel HPlabel;
	JLabel name_label;
	JLabel blue;
	JLabel HP ;
	JLabel def;
	JLabel att;
	JLabel skill4;
	JLabel skill3;
	JLabel skill2;
	JTextArea textArea;
	JLabel skill1;
	JLabel bodylabel;
	private JLabel lblNewLabel_1;
	JButton nextbutton;
	JButton prevbutton;
	BaseHero xinlin;
	BaseHero guanghua;
	BaseHero dongji;
	BaseHero jianwei;
	BaseHero zhiguo;
	BaseHero zhihai;
	int selectHero=0;
	JLabel selectHeroLabel;
	private JLabel label;
	private JLabel label_1;
	private JLabel DEX;
	private JLabel luck;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SelectFrame frame = new SelectFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SelectFrame() {
		setTitle("英雄对决-选人");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 323, 388);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 307, 350);
		contentPane.add(panel);
		panel.setLayout(null);
		
		selectHeroLabel = new JLabel("我方选人");
		selectHeroLabel.setFont(new Font("新宋体", Font.BOLD | Font.ITALIC, 18));
		selectHeroLabel.setBounds(122, 0, 170, 37);
		panel.add(selectHeroLabel);
		
		enterGame = new JButton("进入游戏");
		enterGame.setBounds(175, 47, 103, 29);
		enterGame.addActionListener(new buttonAction());
		panel.add(enterGame);
 
		prevbutton = new JButton("");
		prevbutton.setIcon(new ImageIcon("image/QQ图片20150329192817.png"));
		prevbutton.addActionListener(new buttonAction());
		prevbutton.setBounds(27, 47, 27, 29);
		panel.add(prevbutton);
		
		nextbutton = new JButton("");
		nextbutton.addActionListener(new buttonAction());
		nextbutton.setIcon(new ImageIcon("image/QQ图片20150329192741.png"));
		nextbutton.setBounds(115, 47, 27, 29);
		panel.add(nextbutton);
		
		name_label = new JLabel(" 广华");
		name_label.setFont(new Font("宋体", Font.BOLD, 16));
		name_label.setBounds(60, 47, 55, 29);
		panel.add(name_label);
		
		head_label = new JLabel("");
		head_label.setIcon(new ImageIcon("image/ghhead.jpg"));
		head_label.setBounds(10, 96, 60, 70);
		panel.add(head_label);

		HPlabel = new JLabel("  血：");
		HPlabel.setBounds(80, 97, 38, 21);
		panel.add(HPlabel);
		
		bluelabel = new JLabel("  蓝：");
		bluelabel.setBounds(80, 122, 38, 21);
		panel.add(bluelabel);

		HP = new JLabel("850");
		HP.setForeground(Color.GREEN);
		HP.setBounds(118, 100, 45, 18);
		panel.add(HP);
		
		blue = new JLabel("300");
		blue.setForeground(Color.GREEN);
		blue.setBounds(118, 122, 45, 21);
		panel.add(blue);
		
		JLabel attlabel = new JLabel("  攻击力：");
		attlabel.setBounds(152, 100, 70, 21);
		panel.add(attlabel);
		
		JLabel deflabel = new JLabel("  防御力：");
		deflabel.setBounds(152, 125, 70, 21);
		panel.add(deflabel);

		att = new JLabel("80");
		att.setForeground(Color.GREEN);
		att.setBounds(211, 102, 45, 18);
		panel.add(att);
		
		def = new JLabel("28");
		def.setForeground(Color.GREEN);
		def.setBounds(211, 125, 45, 18);
		panel.add(def);

		bodylabel = new JLabel("New label");
		bodylabel.setIcon(new ImageIcon("image/5.jpg"));
		bodylabel.setBounds(10, 189, 73, 92);
		panel.add(bodylabel);
		
		skill1 = new JLabel("技能一");
		skill1.setBounds(90, 214, 81, 21);
		panel.add(skill1);
		
		textArea = new JTextArea();
		textArea.setLineWrap(true);
		textArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
		textArea.setBounds(5, 279, 287, 61);
		panel.add(textArea);
		textArea.setText("呵呵");
		
		skill2 = new JLabel("技能一");
		skill2.setBounds(175, 214, 81, 21);
		panel.add(skill2);
		
		skill3 = new JLabel("技能一");
		skill3.setBounds(90, 231, 81, 21);
		panel.add(skill3);
		
		skill4 = new JLabel("技能一");
		skill4.setBounds(175, 231, 81, 21);
		panel.add(skill4);
		
		//为技能label注册鼠标监听事件
		skill1.addMouseListener(new Mouselistener());
		skill2.addMouseListener(new Mouselistener());
		skill3.addMouseListener(new Mouselistener());
		skill4.addMouseListener(new Mouselistener());
		
		//设置技能背景可见
		skill1.setOpaque(true);
		skill2.setOpaque(true);
		skill3.setOpaque(true);
		skill4.setOpaque(true);
		
		//技能label创建边框
		skill1.setBorder(BorderFactory.createLineBorder(Color.black));
		skill2.setBorder(BorderFactory.createLineBorder(Color.black));
		skill3.setBorder(BorderFactory.createLineBorder(Color.black));
		skill4.setBorder(BorderFactory.createLineBorder(Color.black));
		
		lblNewLabel_1 = new JLabel("技能：");
		lblNewLabel_1.setForeground(Color.LIGHT_GRAY);
		lblNewLabel_1.setBackground(Color.WHITE);
		lblNewLabel_1.setBounds(88, 189, 54, 15);
		panel.add(lblNewLabel_1);
		
		label = new JLabel("  敏捷：");
		label.setBounds(80, 148, 55, 21);
		panel.add(label);
		
		label_1 = new JLabel("  运气：");
		label_1.setBounds(152, 148, 70, 21);
		panel.add(label_1);
		
		DEX = new JLabel("1");
		DEX.setForeground(Color.GREEN);
		DEX.setBounds(128, 148, 45, 21);
		panel.add(DEX);//敏捷
		
		luck = new JLabel("高");
		luck.setForeground(Color.GREEN);
		luck.setBounds(211, 148, 45, 18);
		panel.add(luck);//运气
		//创建相应英雄
		//hero = new Xinlin();
		//hero = new Guanghua();
		initHero();//初始化英雄
		getHero();//得到英雄
		initHeroAttribute();
		setLocationRelativeTo(null);//设置居中
	}
	public void getHero(){
		hero=null;
		switch(ordernum){
		case 1:
			hero = xinlin;
			break;
		case 2:
			hero = guanghua;
			break;
		case 3:
			hero = dongji;
			break;
		case 4:
			hero = jianwei;
			break;
		case 5:
			hero = zhiguo;
			break;
		case 6:
			hero = zhihai;
			break;
		}
	}
	//
	public void initHeroAttribute(){
		name_label.setText(hero.getName());
		head_label.setIcon(new ImageIcon(hero.getHeadpath()));
		HP.setText(hero.getHP()+"");
		blue.setText(hero.getBlue()+"");
		att.setText(hero.getATT()+"");
		def.setText(hero.getDEF()+"");
		DEX.setText(hero.getDEX()+"");
		luck.setText(hero.getMyluck());
		bodylabel.setIcon(new ImageIcon(hero.getBodypath()));
		skill1.setText(hero.getSname1());
		skill2.setText(hero.getSname2());
		skill3.setText(hero.getSname3());
		skill4.setText(hero.getSname4());
		textArea.setText(hero.getDescribe_hero());
	}
	class Mouselistener implements MouseListener{
		

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
		 */
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
		 */
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
		 */
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
		 */
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			// TODO Auto-generated method stub
			 if(e.getSource()==skill1){
				 skill1.setBackground(Color.green);
				 skill2.setBackground(Color.white);
				 skill3.setBackground(Color.white);
				 skill4.setBackground(Color.white);
				 textArea.setText(hero.getDescribe_skill1());
			 }
			 else if(e.getSource()==skill2){
				 skill1.setBackground(Color.white);
				 skill2.setBackground(Color.green);
				 skill3.setBackground(Color.white);
				 skill4.setBackground(Color.white);
				 textArea.setText(hero.getDescribe_skill2());
			 }
			 else if(e.getSource()==skill3){
				 skill1.setBackground(Color.white);
				 skill2.setBackground(Color.white);
				 skill3.setBackground(Color.green);
				 skill4.setBackground(Color.white);
				 textArea.setText(hero.getDescribe_skill3());
			 }
			 else if(e.getSource()==skill4){
				 skill1.setBackground(Color.white);
				 skill2.setBackground(Color.white);
				 skill3.setBackground(Color.white);
				 skill4.setBackground(Color.green);
				 textArea.setText(hero.getDescribe_skill4());
			 }
		}

		/* (non-Javadoc)
		 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
		 */
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			textArea.setText(hero.getDescribe_hero());
			skill1.setBackground(Color.white);
			 skill2.setBackground(Color.white);
			 skill3.setBackground(Color.white);
			 skill4.setBackground(Color.white);
		}
	}
	class buttonAction implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if(e.getSource()==prevbutton){
				ordernum--;
				if(ordernum<1){
					ordernum=hero_sum;
				}
				getHero();
				initHeroAttribute();
			}else if(e.getSource()==nextbutton){
				ordernum++;
				if(ordernum>hero_sum){
					ordernum=1;
				}
				getHero();
				initHeroAttribute();
			}else if(e.getSource()==enterGame){
				if(hero2==hero){
					JOptionPane.showMessageDialog(null,"这个英雄已被选择，请重新选择");
					return;
				}
				System.out.println(selectHero);
				selectHero++;
				if(selectHero==2){
					MainFrame mainFrame=new MainFrame(hero2,hero);
					mainFrame.setVisible(true);
					dispose();
				}
				selectHeroLabel.setText("挑战的对手");
				hero2=hero;
			}
		}
		
	}
	
	public void initHero(){
		xinlin = new Xinlin();
		guanghua = new Guanghua();
		dongji = new Dongji();
		jianwei = new Jianwei();
		zhiguo = new Zhiguo();
		zhihai = new Zhihai();
	}
}
